﻿package exercise2;

import java.util.ArrayList;
import java.util.List;

public class Test1 {

	public static void main(String[] args) {
		Dog dog1=new Dog("欧欧", "雪纳瑞");
		Dog dog2=new Dog("亚亚", "拉布拉多");
		Dog dog3=new Dog("美美", "雪纳瑞");
		Dog dog4=new Dog("菲菲", "拉布拉多");
		//创建ArrayList集合对象并把4个狗狗对象放入其中
		List dogs=new ArrayList();
		dogs.add(dog1);
		dogs.add(dog2);
		dogs.add(dog3);
		dogs.add(dog4);
		dogs.add(2, dog4);//添加dog4到指定位置
		//输出集合中狗狗的数量
		System.out.println("共计有"+dogs.size()+"条狗狗。");
		//通过数组遍历集合显示各条狗狗信息
		System.out.println("分别是:");
		for (int i = 0; i < dogs.size(); i++) {
			Dog dog=(Dog) dogs.get(i);
			System.out.println(dog.getName()+"\t"+dog.getStrain());
		}
	}

}
